uni.$u.http.setConfig((config) => {
	/* config 为默认全局配置*/
	config.baseURL = "http://192.168.110.243:5000"; /* 根域名 */
	config.timeout = 180000
	return config
})

// 请求拦截
uni.$u.http.interceptors.request.use((config) => {
	config.header['Tenant-Id'] = '2'
	//请求接口白名，在白名单中的url不携带token
	const whiteList = ['/sys/mLogin', '/sys/phoneLogin', '/portal/rlYun/sms/sendWeiXin', '/sys/user/register'];
	//不在白名单的接口自动拼接token
	if (!whiteList.includes(config.url)) {
		config.header['X-Access-Token'] = uni.getStorageSync('token')
	}

	return config
}, config => { // 可使用async await 做异步操作
	return Promise.reject(config)
})

//响应拦截器
uni.$u.http.interceptors.response.use((response) => {
	const {
		code,
		message,
		success
	} = response.data;
	switch (code) {
		//传参异常
		case 401:
			uni.showToast({
				title: message,
				icon: 'none',
				duration: 2000
			});
			//跳转至登录页
			uni.reLaunch({
				url: '/pages/login/login'
			});
			return Promise.reject(response);
			//系统错误
		case 500:
			uni.showToast({
				title: message,
				icon: 'none',
				duration: 2000
			});
			return Promise.reject(response);
	}
	return response.data
}, (response) => {
	uni.showToast({
		title: '服务器发生错误',
		icon: 'error',
		duration: 2000
	});
	return Promise.reject(response)
})